package com.sg.business.commons.sorter;

import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;

import com.sg.business.model.etl.IndicatorData;

public class IndicatorSorter extends ViewerSorter {
	private static final int PRJDELAY = 1;
	private static final int OPERTE = 2;
	private static final int PRJCHANGE = 3;
	private static final int PRJOVER = 4;
	private static final int PRJACCURACY = 5;

	public static final IndicatorSorter PRJDELAY_ASC = new IndicatorSorter(
			PRJDELAY);
	public static final IndicatorSorter PRJDELAY_DESC = new IndicatorSorter(
			-PRJDELAY);
	public static final IndicatorSorter OPERTE_ASC = new IndicatorSorter(OPERTE);
	public static final IndicatorSorter OPERTE_DESC = new IndicatorSorter(
			-OPERTE);
	public static final IndicatorSorter PRJCHANGE_ASC = new IndicatorSorter(
			PRJCHANGE);
	public static final IndicatorSorter PRJCHANGE_DESC = new IndicatorSorter(
			-PRJCHANGE);
	public static final IndicatorSorter PRJOVER_ASC = new IndicatorSorter(
			PRJOVER);
	public static final IndicatorSorter PRJOVER_DESC = new IndicatorSorter(
			-PRJOVER);
	public static final IndicatorSorter PRJACCURACY_ASC = new IndicatorSorter(
			PRJACCURACY);
	public static final IndicatorSorter PRJACCURACY_DESC = new IndicatorSorter(
			-PRJACCURACY);

	private int sortType;

	private IndicatorSorter(int sortType) {
		this.sortType = sortType;
	}

	@Override
	public int compare(Viewer viewer, Object obj1, Object obj2) {
		IndicatorData data1 = (IndicatorData) obj1;
		IndicatorData data2 = (IndicatorData) obj2;
		switch (sortType) {
		case PRJDELAY: {
			double d1 = data1.getPrjdelay();
			double d2 = data2.getPrjdelay();
			return Double.compare(d1, d2);
		}
		case -PRJDELAY: {
			double d1 = data1.getPrjdelay();
			double d2 = data2.getPrjdelay();
			return Double.compare(d2, d1);
		}
		case OPERTE: {
			double o1 = data1.getOperate();
			double o2 = data2.getOperate();
			return Double.compare(o1, o2);
		}
		case -OPERTE: {
			double o1 = data1.getOperate();
			double o2 = data2.getOperate();
			return Double.compare(o2, o1);
		}
		case PRJCHANGE: {
			double c1 = data1.getPrjchange();
			double c2 = data2.getPrjchange();
			return Double.compare(c1, c2);
		}
		case -PRJCHANGE: {
			double c1 = data1.getPrjchange();
			double c2 = data2.getPrjchange();
			return Double.compare(c2, c1);
		}
		case PRJOVER: {
			double o1 = data1.getPrjover();
			double o2 = data2.getPrjover();
			return Double.compare(o1, o2);
		}
		case -PRJOVER: {
			double o1 = data1.getPrjover();
			double o2 = data2.getPrjover();
			return Double.compare(o2, o1);
		}
		case PRJACCURACY: {
			double a1 = data1.getPrjbudgetaccuracy();
			double a2 = data2.getPrjbudgetaccuracy();
			return Double.compare(a1, a2);
		}
		case -PRJACCURACY: {
			double a1 = data1.getPrjbudgetaccuracy();
			double a2 = data2.getPrjbudgetaccuracy();
			return Double.compare(a2, a1);
		}
		}
		return 0;
	}
}
